# _*_ coding : utf-8 _*_
# @Time: 2024/10/11 11:36
# @Author : 石文帅	
# @File : testcase06网格化管理.py
# @Project : python_slfh


from server.slfhWorkbench import *
from selenium.webdriver.chrome.service import Service
from xpathDictionary.slfhXpath import *


class test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.wd = webdriver.Chrome(service=Service(driver_path))
        cls.wd.get(url_path)
        cls.wd.maximize_window()
        login(cls.wd)

    @classmethod
    def tearDownClass(cls):
        cls.wd.quit()
        log.info('----------------------------------------------------------')

    def testcase06网格化管理(self):
        """
        网格化管理
        :return:
        """
        log.info('test6_网格化管理')
        search_menu(self.wd, '网格化管理')
        edit_grid(self.wd, '测试网格旧', '测试网格新', '2', ['张三', '田震琪', '王友志'])

        locate_click(self.wd, grid['网格人员'])
        log.info('断言测试网格旧已经改名无法搜索到')
        search_grid(self.wd, grid_name='测试网格旧')
        assert_true(element_exist(self.wd, grid['暂无数据']))

        log.info('断言测试网格新可以搜索到')
        search_grid(self.wd, grid_name='测试网格新')
        assert_false(element_exist(self.wd, grid['暂无数据']))

        log.info('搜索张三、南岸区、测试网格新、护林员 并断言 和 单条删除')
        search_grid(self.wd, people_name='张三', up_grid_name='南岸区', grid_name='测试网格新', post='护林员')
        actualise = ['迎龙镇-张三', '南岸区', '测试网格新', '护林员']
        assert_list_elements(self.wd, grid['网格人员第一行'], actualise)
        log.info('单条删除 张三')
        locate_click(self.wd, grid['网格人员-第一条删除'])
        locates_last_click(self.wd, grid['网格人员-删除取消'])
        locate_click(self.wd, grid['搜索-查询'])
        assert_list_elements(self.wd, grid['网格人员第一行'], actualise)

        locate_click(self.wd, grid['网格人员-第一条删除'])
        locate_click(self.wd, grid['网格人员-删除关闭'])
        locate_click(self.wd, grid['搜索-查询'])
        assert_list_elements(self.wd, grid['网格人员第一行'], actualise)

        locate_click(self.wd, grid['网格人员-第一条删除'])
        locate_click(self.wd, grid['网格人员-删除确认'])
        locate_click(self.wd, grid['搜索-查询'])
        assert_true(element_exist(self.wd, grid['暂无数据']))

        log.info('搜索测试网格新 批量删除')
        search_grid(self.wd, grid_name='测试网格新')
        log.info('删除前先断言筛选有没有问题')
        assert_str_elements(self.wd, '测试网格新', grid['网格人员网格名称列'])
        log.info('全选后 批量删除')
        locate_click(self.wd, grid['网格人员-全选'])
        locate_click(self.wd, grid['网格人员-批量删除'])
        locates_last_click(self.wd, grid['网格人员-删除取消'])
        assert_false(element_exist(self.wd, grid['暂无数据']))

        locate_click(self.wd, grid['网格人员-批量删除'])
        locate_click(self.wd, grid['网格人员-删除关闭'])
        assert_false(element_exist(self.wd, grid['暂无数据']))

        locate_click(self.wd, grid['网格人员-批量删除'])
        locate_click(self.wd, grid['网格人员-删除确认'])
        locate_click(self.wd, grid['搜索-查询'])
        assert_true(element_exist(self.wd, grid['暂无数据']))

        log.info('恢复数据')
        locate_click(self.wd, grid['网格管理'])
        edit_grid(self.wd, '测试网格新', '测试网格旧', '1', ['蒋先生', '王友志', '刘念'])
